package com.wind.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.wind.entity.TestPaper;
import com.wind.entity.TopicChoice;
import com.wind.service.ITestPaperService;
import com.wind.service.ITopicChoiceService;
import com.wind.vo.Json;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/topic_choice")
public class TopicChoiceController extends BaseController{

    @Autowired
    ITopicChoiceService topicChoiceService;

    @PostMapping("/page")
    public Json page(@RequestBody String body){
        JSONObject json = JSONObject.parseObject(body);
        String name = json.getString("nickname");
        int current = json.getIntValue("current");
        int size = json.getIntValue("size");
        if (current == 0) current = 1;
        if (size == 0) size = 10;
        Page<TopicChoice> page = topicChoiceService.selectPage(new Page<>(current, size),
                new EntityWrapper<TopicChoice>().like("test_name", name));
        return Json.succ().data("page", page);
    }

}
